package com.yuyou.fn.educational.service.impl;

import com.github.wens.framework.service.impl.SuperServiceImpl;
import com.github.wens.mybatisplus.examples.Example;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.educational.entity.ClassLecture;
import com.yuyou.fn.educational.entity.TeacherRemuneration;
import com.yuyou.fn.educational.mapper.TeacherRemunerationMapper;
import com.yuyou.fn.educational.service.IClassLectureService;
import com.yuyou.fn.educational.service.ITeacherRemunerationService;
import com.yuyou.fn.educational.vo.ClassRemunerationRankVo;
import com.yuyou.fn.educational.vo.ClassTimeRankVo;
import com.yuyou.fn.educational.vo.StudentAmountRankVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 *
 * TeacherRemuneration 表数据服务层接口实现类
 *
 */
@Service
public class TeacherRemunerationServiceImpl extends SuperServiceImpl<TeacherRemunerationMapper, TeacherRemuneration,Long> implements ITeacherRemunerationService {

    @Resource
    private IClassLectureService classLectureService;

    @Override
    public void addTeacherRemuneration(Long areaTeamId, Long busTeamId, Long periodId, Long classId, Long classLectureId, Long teacherId, int classTime, BigDecimal amount , int studentAmount ) {
        TeacherRemuneration teacherRemuneration = new TeacherRemuneration();
        ClassLecture classLecture=classLectureService.findById(classLectureId);
        teacherRemuneration.setAmount(amount);
        teacherRemuneration.setAreaTeamId(areaTeamId);
        teacherRemuneration.setBusTeamId(busTeamId);
        teacherRemuneration.setPeriodId(periodId);
        teacherRemuneration.setClassId(classId);
        teacherRemuneration.setClassLectureId(classLectureId);
        teacherRemuneration.setTeacherId(teacherId);
        teacherRemuneration.setClassTime(classTime);
        teacherRemuneration.setCreateTime(TimeUtils.now());
        teacherRemuneration.setUpdateTime(TimeUtils.now());
        teacherRemuneration.setStudentAmount(studentAmount);
        teacherRemuneration.setClassDate(classLecture.getClassDate());
        try{
            insertSelective(teacherRemuneration);
        }catch (Exception e ){
            //
        }


    }

    @Override
    public List<TeacherRemuneration> findMyClassRemuneration(Long periodId, Long teacherId) {
        Example<TeacherRemuneration> example = TeacherRemuneration.createExample();
        example.createCriteria().andEqualTo("periodId",periodId ).andEqualTo("teacherId" , teacherId ) ;
        return findListByExample(example);
    }

    @Override
    public List<ClassRemunerationRankVo> classRemunerationRank(Long areaTeamId, Long periodId ) {
        return autoMapper.classRemunerationRank(areaTeamId,periodId  );
    }

    @Override
    public List<ClassTimeRankVo> classTimeRank(Long areaTeamId, Long periodId  ) {
        return autoMapper.classTimeRank( areaTeamId,  periodId  );
    }

    @Override
    public ClassRemunerationRankVo myClassRemunerationRank(Long areaTeamId, Long periodId, Long teacherId) {
        return autoMapper.myClassRemunerationRank( areaTeamId,  periodId,  teacherId);
    }

    @Override
    public List<TeacherRemuneration> findMyClassRemuneration(Long teacherId, Date start, Date end) {
        Example<TeacherRemuneration> example = TeacherRemuneration.createExample();
        example.createCriteria().andEqualTo("teacherId" , teacherId ).andBetween("classDate" , start,end ) ;
        return findListByExample(example);
    }

    @Override
    public ClassTimeRankVo myClassTimeRank(Long areaTeamId, Long periodId, Long teacherId) {
        return autoMapper.myClassTimeRank(areaTeamId,periodId,teacherId);
    }

    @Override
    public List<StudentAmountRankVo> studentAmountRank(Long areaTeamId, Long periodId) {
        return autoMapper.studentAmountRank(areaTeamId,periodId);
    }

    @Override
    public StudentAmountRankVo myStudentAmountRank(Long areaTeamId, Long periodId, Long teacherId) {
        return autoMapper.myStudentAmountRank(areaTeamId,periodId,teacherId);
    }



}